<?php

namespace App\Http\Controllers\Post;

use App\Models\ItemCatlog;
use App\Models\PostContent;
use App\Models\PostItem;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class DetailController extends Controller
{
    /**
     * @param int $aid
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public function index($aid=0){

        PostItem::where('aid', $aid)->increment('views');

        $post = PostItem::find($aid);
        $this->assign([
            'aid'=>$aid,
            'post'=>$post,
            'content'=>$post->content,
            'media'=>$post->media,
            'images'=>$post->images()->get(),
            'catlog'=>$post->catlog
        ]);

        $this->assign([
            'keywords'=>$post->tags ? implode(',', $post->tags) : setting('keywords'),
            'description'=>$post->summary ? $post->summary : setting('description'),
            'newPostList'=>PostItem::where('status',1)->orderByDesc('aid')->limit(10)->get(),
            'hotPostList'=>PostItem::where('status',1)->orderByDesc('views')->limit(10)->get(),
        ]);

        return $this->view('post.'.$post->type);
    }
}
